package com.application.tourapp;

import java.util.ArrayList;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

import com.application.tourapp.async.TypesAsyncActivity;
import com.application.tourapp.baseadapter.TypeListBaseAdapter;
import com.application.tourapp.dal.TypeDAL;
import com.application.tourapp.model.Type;

/**
 * Cette activite est pour les types
 * 
 * @author Ramy
 *
 */

public class TypesActivity extends GenericActivity {
	public ListView listTypes;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.types_activity);
		setHeader(getResources().getString(R.string.Types), true, true);
		Context context = getApplicationContext();
		new TypesAsyncActivity(this).execute();
		ArrayList<Type> typeDetails = GetSearchResults(context);

		listTypes = (ListView) findViewById(R.id.listV_main);
		listTypes.setAdapter(new TypeListBaseAdapter(this, typeDetails));
		listTypes.setOnItemClickListener(new OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> a, View v, int position,
					long id) {
				Object o = listTypes.getItemAtPosition(position);
				Type objType = (Type) o;
				System.out.println("The type name = " + objType.getName());
				Intent touristicItemsScreenIntent = new Intent(
						getApplicationContext(), TouristicItemsActivity.class);
				ItemsGroupActivity parentActivity = (ItemsGroupActivity) getParent();
				touristicItemsScreenIntent.putExtra("id_type",
						Integer.toString(objType.getId()));
				parentActivity.startChildActivity("TouristicItemsActivity",
						touristicItemsScreenIntent);
			}
		});
	}

	public ArrayList<Type> GetSearchResults(Context context) {
		return new TypeDAL(context).getAlltypes();
	}
}